<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
  <% include("/include/header3.html",{"title":"系统组织编辑页"}){} %>
</head>
<body>

<div id="app">
  <div class="mainBox ">
    <div class="main-container layui-card">
      <div class="layui-card-body">

         <t-form ref="formRef" :data="form" :rules="rules" :disabled="loading" scroll-to-first-error="smooth" colon requiredMark>
           <t-row :gutter="[50,20]">
            <t-col :xs="12" :sm="6">
              <t-form-item label="pid" name="pid">
                <t-input v-model="form.pid" placeholder="请输入pid" :maxlength="19" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="pids" name="pids">
                <t-input v-model="form.pids" placeholder="请输入pids" :maxlength="300" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="组织名称" name="name">
                <t-input v-model="form.name" placeholder="请输入组织名称" :maxlength="50" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="组织代码" name="code">
                <t-input v-model="form.code" placeholder="请输入组织代码" :maxlength="50" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="负责人" name="leader">
                <t-input v-model="form.leader" placeholder="请输入负责人" :maxlength="20" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="联系电话" name="phone">
                <t-input v-model="form.phone" placeholder="请输入联系电话" :maxlength="11" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="邮箱" name="email">
                <t-input v-model="form.email" placeholder="请输入邮箱" :maxlength="50" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="排序" name="sort">
                <t-input v-model="form.sort" placeholder="请输入排序" :maxlength="10" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="状态（1-启用，0-停用）" name="status">
                <t-input v-model="form.status" placeholder="请输入状态（1-启用，0-停用）" :maxlength="3" show-limit-number clearable></t-input>
              </t-form-item>
            </t-col>
          </t-row>
        </t-form>

      </div>
    </div>
  </div>
  <div class="bottom">
    <t-space class="button-container ">
      <t-button :loading="loading" theme="primary" @click="onSave"><i class="layui-icon layui-icon-ok mr-5 text-size-14"></i> 保存</t-button>
      <t-button theme="warning" @click="closeBtn.close"><i class="layui-icon mr-5 text-size-14" :class="closeBtn.i"></i> {{closeBtn.t}}</t-button>
    </t-space>
  </div>
</div>

<script>
  const PATH_URL = "sys/org/";
</script>

<script>

  setupVue("#app", {
    setup() {
      // 表单相关
      const loading = Vue.ref(true);
      const formRef = Vue.ref(null);
      const form = Vue.ref({
        pid: undefined,
        pids: undefined,
        name: undefined,
        code: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        sort: undefined,
        status: undefined,
      });
      const rules = {
        sort: [$required('请输入排序')],
        status: [$required('请输入状态（1-启用，0-停用）')],
      };
      // 获取表单数据
      const getForm = (id) => req(axiosGet, PATH_URL + "getInfo", {id}, (res) => {
        if (res.code === 200) {
          form.value = res.data;
        } else {
          $baseAlert(res.msg, () => closeBtn.value.close());
        }
      }, loading);
      const LyData = getLayerData();
      if (LyData && LyData.id) getForm(LyData.id);
      if (ID) getForm(ID);
      else loading.value = false;


      // 点击保存
      const onSave = () => {
        formRef.value.validate().then((validateResult) => {
          if (validateResult && Object.keys(validateResult).length) {
            const firstError = Object.values(validateResult)[0]?.[0]?.message;
            $baseMsg(firstError);
          } else {
            let REQ;
            let URL;
            if (form.value.id) {
              REQ = axiosPut, URL = PATH_URL + "edit";
            } else {
              REQ = axiosPost, URL = PATH_URL + "add";
            }
            req(REQ, URL, form, (res) => {
              $baseAlert(res.msg, () => {
                if (res.code === 200) closeLayer(parent.reloadData);
              })
            }, loading);
          }
        });
      }

      const closeBtn = useCloseBtn();
      return {
        closeBtn,
        formRef, loading, form, rules,
        onSave,

      }

    }
  });
</script>


</body>
</html>
